//
//  BK_my_addressSwitchCell.m
//  bestkeep
//
//  Created by bj on 2016/11/9.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BK_my_addressSwitchCell.h"
#import "BKMyCommon.h"
#import "Masonry.h"
#import "BK_Adress_Tool.h"


@implementation BK_my_addressSwitchCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)initlizeValue:(CellModel *)model {
    self.optionLabel.text = model.title;
    self.delegate = model.delegate;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = BK_MY_COLOR_06;
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left);
            make.right.equalTo(self.contentView.mas_right);
            make.top.equalTo(self.contentView.mas_top);
            make.height.equalTo(@(1.5));
        }];
        
        /*
         * 设为默认地址
         */
        _optionLabel = [[UILabel alloc] initWithFrame:CGRectZero];
//        _optionLabel.backgroundColor=[UIColor  yellowColor];
        [self.contentView addSubview:_optionLabel];
        _optionLabel.font = [UIFont systemFontOfSize:15.0];
        _optionLabel.textColor = BK_MY_COLOR_07;
        [_optionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).mas_offset(Address_BackGauge);
            make.centerY.equalTo(self.contentView.mas_centerY);
        }];

        _defaultAddressSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:_defaultAddressSwitch];
        [self.defaultAddressSwitch addTarget:self action:@selector(switch_Action:) forControlEvents:UIControlEventValueChanged];
        [_defaultAddressSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).mas_offset(-Address_BackGauge);
            make.centerY.equalTo(self.contentView.mas_centerY);
        }];
    }
    return self;
}

- (void)switch_Action:(UISwitch *)sw {
    if ([self.delegate respondsToSelector:@selector(switchStatusInCell:)]) {
        [self.delegate switchStatusInCell:self.defaultAddressSwitch];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
